#ifndef _timberyard_exception_h_
#define _timberyard_exception_h_

#include <timberyard/backtrace.h>
#include <timberyard/utils.h>
#include <exception>
#include <string>
#include <list>
#include <iostream>

// copied merciless from boost, without the baggage.
// TODO: wrap this in an ifdef
#define THROW_LOCATION Timberyard::ThrowTag("File",__FILE__)<<Timberyard::ThrowTag("Line",Timberyard::ToString(__LINE__))

namespace Timberyard {

class ThrowTag {
	public:
		ThrowTag(const std::string& name, const std::string& value) : m_name(name), m_value(value) {};
		virtual std::string Display() const;
		virtual ~ThrowTag() {};
	private:
		std::string m_name;
		std::string m_value;
};


class Exception : public std::exception {
	protected:
		Backtrace m_stack;
		std::string m_text;
		std::list<ThrowTag> m_tags;
	public:
		Exception(int errnum);
		Exception();
		Exception(const std::string& s) : m_stack(), m_text(s),m_tags() {std::cerr << m_text<<std::endl; }
		Exception(const char* s) : m_stack(), m_text(s),m_tags() {std::cerr << m_text<<std::endl; }
		virtual const char* what() const throw();
		virtual ~Exception() throw () {}
		Exception& operator<<(const ThrowTag& t);
};

} //namespace Timberyard

#endif // #ifndef _timberyard_exception_h_
